<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  users
 */

class m_users_documents_Group extends m_users_documents_GroupBase
{
	/**
	 * @return m_users_documents_Group
	 */
	public static function createNew()
	{
		return new self();
	}
	
	/**
	 * @return m_users_documents_Group
	 */
	public static function getInstanceByUniqueId($id)
	{
		$lang = f_core_Context::getInstance()->getLang();
		$cache = f_core_Cache::getInstance();
		
		$key = $cache->getDocumentCacheKey($id, $lang);
		
		if($cache->hasCache($key))
		{
			return $cache->getCacheContent($key);
		}
		
		$object = new self($id);
		
		$cache->putInCache($key, $object);
		
		return $object;
	}
	
	public function canSlide()
	{
		return true;
	}
	
	public function getEditUrl($lang = null, $tabName = null)
	{		
		if(is_null($lang))
		{
			$lang = f_core_Request::getInstance()->getParameter("docLang");
		}
		
		if(is_null($tabName))
		{
			$tabName = "users";
		}
		
		return f_core_Routing::getUrl("groupEdit", array("tabName" => $tabName, "docId" => $this->getUniqueId(), "docLang" => strtolower($lang)));
	}

	public function getRightUrl($lang = null, $subTabName = null)
	{
		if(is_null($lang))
		{
			$lang = f_core_Request::getInstance()->getParameter("docLang");
		}

		if(is_null($subTabName))
		{
			$tabName = "website";
		}

		return f_core_Routing::getUrl("groupRightEdit", array("subTabName" => $subTabName, "docId" => $this->getUniqueId(), "docLang" => strtolower($lang)));
	}
	
	public function getDeleteUrl($lang = null)
	{
		if(is_null($lang))
		{
			$lang = f_core_Request::getInstance()->getParameter("docLang");
		}

		return f_core_Routing::getUrl("deleteGroup", array("docId" => $this->getUniqueId(), "docLang" => strtolower($lang)));
	}	
	
	public function getIcon()
	{
		return "group.png";
	}

    public function getUsersNb()
    {
        $relManager = f_relation_Manager::getInstance();
        return count($relManager->getChildsIdsByDocTypeRecursive($this->getUniqueId(), array('modules_users/User'), $this->getLang()));
    }

    public function getBoSearchIcon()
    {
        return m_medias_services_MediaService::getInstance()->getIconPath($this->getIcon());
    }
}